//
//  LGMedicineUntowardEffectCell.m
//  BreathTrainingTool
//
//  Created by 1234 on 2024/7/15.
//  药物 -- 不良反应

#import "LGMedicineUntowardEffectCell.h"

@interface LGMedicineUntowardEffectCell()

/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *countLabel;
/**   */
@property (nonatomic , strong)UIView *baseLine;
/**   */
@property (nonatomic , strong)UIView *percentLine;

@end

@implementation LGMedicineUntowardEffectCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.type = LGPositionTypeMiddle;
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    self.titleLabel.text = LGNSString(dataDic[@"name"]);
    self.countLabel.text = [NSString stringWithFormat:@"本月出现%@次",dataDic[@"count"]];
    CGFloat percent = (CGFloat)[dataDic[@"count"] integerValue] / [dataDic[@"total"] integerValue];
    CGFloat lineW = (Screen_W-viewPix(64))*percent;
    self.percentLine.frame = CGRectMake(0, 0, lineW, viewPix(4));
    NSString *color = [self.titleLabel.text isEqualToString:@"无不良反应"]?@"#11CCAA":@"#DD3030";
    self.percentLine.backgroundColor = [UIColor colorWithString:color];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.countLabel];
    [self.contentView addSubview:self.baseLine];
    [self.baseLine addSubview:self.percentLine];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.left.equalTo(self.contentView).offset(viewPix(32));
        make.right.equalTo(self.contentView).offset(-viewPix(120));
    }];
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(32));
        make.centerY.equalTo(self.titleLabel);
    }];
    [self.baseLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.right.equalTo(self.countLabel);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(8));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
        make.height.equalTo(@(viewPix(4)));
    }];
}
-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#2B2A37" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _titleLabel;
}

-(UILabel *)countLabel{
    if(!_countLabel){
        _countLabel = [UILabel lableWithText:@"" colorString:@"#606266" textFont:LGFont(14) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _countLabel;
}

-(UIView *)baseLine{
    if(!_baseLine){
        _baseLine = [[UIView alloc]init];
        _baseLine.backgroundColor = [UIColor colorWithString:@"#F4F4F4"];
        _baseLine.cornerRidus = viewPix(2);
        _baseLine.clipsToBounds = YES;
    }
    return _baseLine;
}

-(UIView *)percentLine{
    if(!_percentLine){
        _percentLine = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, viewPix(4))];
        _percentLine.backgroundColor = [UIColor colorWithString:@"#DD3030"];
        _percentLine.cornerRidus = viewPix(2);
    }
    return _percentLine;
}

@end
